import { RouteRecordRaw } from "node_modules/vue-router/dist/vue-router.js";
import router from './index'
// 引入 views 文件夹下所有 vue 文件
const modules = import.meta.glob("@/views/**/*.vue");

let myRoute = [];
const autoload = () => {
  myRoute = [];
  console.log("modules:", modules);
  Object.entries(modules).forEach(([file, module]) => {
    
    // const name = file.split("/").pop()?.split(".")[0];
    
    // console.log(file.split("/views").pop().replace('/index.vue',"").split('/').pop()?.split(".")[0]);
    const name = file.split("/views").pop().replace('/index.vue',"").split('/').pop()?.split(".")[0]
    const path = file.split("/views").pop().replace('/index.vue',"").split('/').pop()?.split(".")[0]
    if(name&&!name.includes('home')&&!name.includes('login')){
      const route = {
        name: name,
        path: `/${path}`,
        component: module,
      } as RouteRecordRaw;
      router.addRoute('home',route)
    }
  });
};

console.log('myRoute',myRoute);
export default autoload;
